#include "Parabole.hpp"

using namespace Ipopt;

Parabole::Parabole(Index dimension) :
	UnconstrainedProblem(dimension) {
}

/** Method to return the starting point for the algorithm */
bool Parabole::get_starting_point(Index n, Number* x) {

	for (Index i = 0; i < n; ++i) {
		x[i] = 3;
	}

	return true;
}

/** Method to return the objective value */
bool Parabole::eval_f(Index n, const Number* x, bool new_x, Number& obj_value) {
	Number sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += x[i] * x[i];
	}
	obj_value = sum;

	return true;
}

/** Method to return the gradient of the objective */
bool Parabole::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) {
	for (int i = 0; i < n; ++i) {
		grad_f[i] = 2 * x[i];
	}
	return true;
}

bool Parabole::get_nlp_info(Index& n, Index& nnz_h_lag) {
	n = dimension;
	nnz_h_lag = 0;

	return true;
}

void Parabole::newX(const Number* x) {
}

